using System;
using System.Runtime.Serialization;
using System.Xml;
using SharpObjects.Interfaces;

namespace SharpObjects.Instantiation.Services
{
    [Serializable]
    [DataContract]
    public class ServiceDescriptor : IServiceDescriptor
    {
        public ServiceDescriptor()
        {
            this.TypeDescriptor = null;
            this.SingletonInstance = null;
        }

        public ServiceDescriptor(ITypeDescriptor typeDescriptor = null)
        {
            this.TypeDescriptor = typeDescriptor;
            this.SingletonInstance = null;
        }

        [DataMember]
        public string ServiceId { get; set; }
        [DataMember]
        public string ServiceVersion { get; set; }
        [DataMember]
        public ITypeDescriptor TypeDescriptor { get; set; }
        [DataMember]
        public bool PreInstantiate { get; set; }
        [DataMember]
        public string[] PreInstantiateVersions { get; set; }
        [DataMember]
        public bool IsSingleton { get; set; }
        public object SingletonInstance { get; set; }

        public virtual IServiceDescriptor Clone()
        {
            ServiceDescriptor clone = new ServiceDescriptor()
                                          {
                                              ServiceId = this.ServiceId,
                                              ServiceVersion = this.ServiceVersion,
                                              TypeDescriptor = this.TypeDescriptor,
                                              PreInstantiate = this.PreInstantiate,
                                              PreInstantiateVersions = this.PreInstantiateVersions,
                                              IsSingleton = this.IsSingleton,
                                              SingletonInstance = null
                                          };

            return clone;
        }
    }
}